package com.acwing.partition11;

import java.io.*;

/**
 * @author `RKC`
 * @date 2021/12/23 10:04
 */
public class AC1075数字转换 {

    //sum[i]表示数字i的约数之和
    private static int[] sum, head, element, next;
    private static int index = 0, answer = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] s = reader.readLine().split("\\s+");
        int n = Integer.parseInt(s[0]);
        sum = new int[n + 1];
        head = new int[n + 1];
        for (int i = 1; i <= n; i++) head[i] = -1;
        element = new int[n + 1];
        next = new int[n + 1];
        //筛选法求出1-n的所有数的约数之和
        for (int i = 1; i <= n; i++) {
            for (int j = 2; j <= n / i; j++) {
                sum[i * j] += i;
            }
        }
        //构建森林
        for (int i = 1; i <= n; i++) {
            if (sum[i] < i) createEdge(sum[i], i);
        }
        dfs(1);
        writer.write(answer + "\n");
        writer.flush();
    }

    private static int dfs(int u) {
        int first = 0, second = 0;
        for (int i = head[u]; i != -1; i = next[i]) {
            int v = element[i];
            //有向图，因此不需要对回到父节点的情况进行判断
            int res = dfs(v) + 1;
            if (res > first) { second = first; first = res; }
            else if (res > second) second = res;
        }
        answer = Math.max(answer, first + second);
        return first;
    }

    private static void createEdge(int u, int v) {
        element[index] = v;
        next[index] = head[u];
        head[u] = index++;
    }
}
